Array.prototype.contains = function(obj) {
    var i = this.length;
    while (i--) {
        if (this[i] === obj) {
            return true;
        }
    }
    return false;
}
///////////////////////////////////////////
//Browser Sniffing.
///////////////////////////////////////////
function isMozilla() {
  return navigator.appName=="Netscape";
}

function isIE() {
  return navigator.appName=="Microsoft Internet Explorer";
}

function isIE6() {
    if (isIE()) {
        var version = navigator.appVersion.split("MSIE");
        var version = parseFloat(version[1]);
        return version === 6;
    }
    return false;
}

function isIEVersion7Upwards() {
    if (isIE()) {
        var version = navigator.appVersion.split("MSIE");
        var version = parseFloat(version[1]);
        return version >= 7;
    }
    return false;
}
///////////////////////////////////////////
//Window Inspection
///////////////////////////////////////////

function getWindowWidth() {
 if (isMozilla())
     return innerWidth;
return document.body.clientWidth;
}

function getWindowHeight() {
if (isMozilla())
     return innerHeight;
return document.body.clientHeight;
}

function getScrollLeft() {
 if (isMozilla()) {
     return window.scrollX;
 }
 return document.body.scrollLeft;
}

function getScrollTop() {
 if (isMozilla()) {
     return window.scrollY;
 }
 return document.body.scrollTop;
}
////////////////////////////////////////
//String Utils
////////////////////////////////////////

function trim(thisStr) {
	// skip leading and trailing whitespace
	// and return everything in between
	thisStr=thisStr.replace(/^\s*(.*)/, "$1");
	thisStr=thisStr.replace(/(.*?)\s*$/, "$1");
	return thisStr;
}
function startsWith(string1,string2) {
  return string1.indexOf(string2)==0;
}
/**
 * replaces all instances of str1 in str with str2
 * note: assumes str2 does not contain str1!
 */
function replaceAll(str,str1,str2) {
    while (str.indexOf(str1)>-1) {
        str = str.replace(str1,str2);
    }
    return str;
}
///////////////////////////////
//Keyboard events
///////////////////////////////

//Contains all key codes
Keys = new Object();

Keys.DOM_VK_BACK_SPACE = 8;
Keys.DOM_VK_ENTER = 13;
Keys.DOM_VK_PAGE_UP = 33;
Keys.DOM_VK_DOWN = 40;
Keys.DOM_VK_INSERT = 45;
Keys.DOM_VK_DELETE = 46;
Keys.DOM_VK_0 = 48;
Keys.DOM_VK_9 = 57;
Keys.DOM_VK_NUMPAD0 = 96;
Keys.DOM_VK_NUMPAD9 = 105;
Keys.DOM_VK_DECIMAL = 110;
Keys.DOM_VK_COMMA = 188;
Keys.DOM_VK_PERIOD = 190;
Keys.DOM_VK_CANCEL = 3;
Keys.DOM_VK_HELP = 6;
Keys.DOM_VK_TAB = 9;
Keys.DOM_VK_CLEAR = 12;
Keys.DOM_VK_RETURN = 13;
Keys.DOM_VK_SHIFT = 16;
Keys.DOM_VK_CONTROL = 17;
Keys.DOM_VK_ALT = 18;
Keys.DOM_VK_PAUSE = 19;
Keys.DOM_VK_CAPS_LOCK = 20;
Keys.DOM_VK_ESCAPE = 27;
Keys.DOM_VK_SPACE = 32;
Keys.DOM_VK_PAGE_DOWN = 34;
Keys.DOM_VK_END = 35;
Keys.DOM_VK_HOME = 36;
Keys.DOM_VK_LEFT = 37;
Keys.DOM_VK_UP = 38;
Keys.DOM_VK_RIGHT = 39;
Keys.DOM_VK_PRINTSCREEN = 44;
Keys.DOM_VK_1 = 49;
Keys.DOM_VK_2 = 50;
Keys.DOM_VK_3 = 51;
Keys.DOM_VK_4 = 52;
Keys.DOM_VK_5 = 53;
Keys.DOM_VK_6 = 54;
Keys.DOM_VK_7 = 55;
Keys.DOM_VK_8 = 56;
Keys.DOM_VK_SEMICOLON = 59;
Keys.DOM_VK_EQUALS = 61;
Keys.DOM_VK_A = 65;
Keys.DOM_VK_B = 66;
Keys.DOM_VK_C = 67;
Keys.DOM_VK_D = 68;
Keys.DOM_VK_E = 69;
Keys.DOM_VK_F = 70;
Keys.DOM_VK_G = 71;
Keys.DOM_VK_H = 72;
Keys.DOM_VK_I = 73;
Keys.DOM_VK_J = 74;
Keys.DOM_VK_K = 75;
Keys.DOM_VK_L = 76;
Keys.DOM_VK_M = 77;
Keys.DOM_VK_N = 78;
Keys.DOM_VK_O = 79;
Keys.DOM_VK_P = 80;
Keys.DOM_VK_Q = 81;
Keys.DOM_VK_R = 82;
Keys.DOM_VK_S = 83;
Keys.DOM_VK_T = 84;
Keys.DOM_VK_U = 85;
Keys.DOM_VK_V = 86;
Keys.DOM_VK_W = 87;
Keys.DOM_VK_X = 88;
Keys.DOM_VK_Y = 89;
Keys.DOM_VK_Z = 90;
Keys.DOM_VK_CONTEXT_MENU = 93;
Keys.DOM_VK_NUMPAD1 = 97;
Keys.DOM_VK_NUMPAD2 = 98;
Keys.DOM_VK_NUMPAD3 = 99;
Keys.DOM_VK_NUMPAD4 = 100;
Keys.DOM_VK_NUMPAD5 = 101;
Keys.DOM_VK_NUMPAD6 = 102;
Keys.DOM_VK_NUMPAD7 = 103;
Keys.DOM_VK_NUMPAD8 = 104;
Keys.DOM_VK_MULTIPLY = 106;
Keys.DOM_VK_ADD = 107;
Keys.DOM_VK_SEPARATOR = 108;
Keys.DOM_VK_SUBTRACT = 109;
Keys.DOM_VK_SUBTRACT_UNDERSCORE_IE = 189;
Keys.DOM_VK_DIVIDE = 111;
Keys.DOM_VK_F1 = 112;
Keys.DOM_VK_F2 = 113;
Keys.DOM_VK_F3 = 114;
Keys.DOM_VK_F4 = 115;
Keys.DOM_VK_F5 = 116;
Keys.DOM_VK_F6 = 117;
Keys.DOM_VK_F7 = 118;
Keys.DOM_VK_F8 = 119;
Keys.DOM_VK_F9 = 120;
Keys.DOM_VK_F10 = 121;
Keys.DOM_VK_F11 = 122;
Keys.DOM_VK_F12 = 123;
Keys.DOM_VK_F13 = 124;
Keys.DOM_VK_F14 = 125;
Keys.DOM_VK_F15 = 126;
Keys.DOM_VK_F16 = 127;
Keys.DOM_VK_F17 = 128;
Keys.DOM_VK_F18 = 129;
Keys.DOM_VK_F19 = 130;
Keys.DOM_VK_F20 = 131;
Keys.DOM_VK_F21 = 132;
Keys.DOM_VK_F22 = 133;
Keys.DOM_VK_F23 = 134;
Keys.DOM_VK_F24 = 135;
Keys.DOM_VK_NUM_LOCK = 144;
Keys.DOM_VK_SCROLL_LOCK = 145;
Keys.DOM_VK_SLASH = 191;
Keys.DOM_VK_BACK_QUOTE = 192;
Keys.DOM_VK_OPEN_BRACKET = 219;
Keys.DOM_VK_BACK_SLASH = 220;
Keys.DOM_VK_CLOSE_BRACKET = 221;
Keys.DOM_VK_QUOTE = 222;
Keys.DOM_VK_META = 224;
///////////////////////////////////////////
//项目根路径
///////////////////////////////////////////
function getRootPath()
{
	return Constant_System_BasePath;
}
//截断字符串
function makelen(sstr,slen)
{
	if(encodeURI(sstr,'utf-8').length <= 149)
	{
		return sstr;
	}
	var makestr='';
	var parity=0;
	var tmpstr='';
	var mslen=sstr.length;
	if(mslen>slen)
	{
		for(var mn=0;mn<slen;mn++) //在要求的长度内
		{
			ss=sstr.substring(mn,1);
			if(ss.charCodeAt()<127) //#为英文
			{
				parity++;
			}
		}
		if(parity%2==1) //#含英文长度为奇数
		{
			if(slen%2==1) //#如果所要求的长度也为奇数
			{
				tmpstr=sstr.substring(0,slen);
			}
			else //#所要求的长度为偶数
			{
				tmpstr=sstr.substring(0,slen-1);
			}
		}
		else //#含英文长度为偶数或者为0，0也为偶数
		{
			if(slen%2==1) //#如果所要求的长度为奇数
			{
				tmpstr=sstr.substring(0,slen-1);
			}
			else //#所要求的长度为偶数
			{
				tmpstr=sstr.substring(0,slen);
			}
		}
		makestr=tmpstr+"..";
	}
	else
	{
		makestr=sstr;
	}
	return makestr;
}
/**
* 时间对象的格式化
*/
Date.prototype.format = function(format)
{
	/*
	* format="yyyy-MM-dd hh:mm:ss";
	*/
	var o = {
		"M+" : this.getMonth() + 1,
		"d+" : this.getDate(),
		"h+" : this.getHours(),
		"m+" : this.getMinutes(),
		"s+" : this.getSeconds(),
		"q+" : Math.floor((this.getMonth() + 3) / 3),
		"S" : this.getMilliseconds()
	}
	
	if (/(y+)/.test(format))
	{
		format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4-RegExp.$1.length));
	}
	for (var k in o)
	{
		if (new RegExp("(" + k + ")").test(format))
		{
			format = format.replace(RegExp.$1, RegExp.$1.length == 1
			? o[k]
			: ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return format;
}